﻿namespace KinonekoSoftware.Studio.Pages.Contents
{

    [Associate(View = typeof(CharacterPickerView), ViewModel = typeof(CharacterPickerViewModel))]
    public partial class CharacterPickerView: ForestDialog
    {
        private CharacterPickerViewModel _vm;
        public CharacterPickerView()
        {
            InitializeComponent();
        }
        
        protected override void OnLoaded()
        {
            _vm = ViewModel<CharacterPickerViewModel>();
            
            
            Items.SelectionMode    =  _vm.IsMultipleSelection ? SelectionMode.Multiple : SelectionMode.Single;
            Items.SelectionChanged += OnSelectionChanged;
            base.OnLoaded();
        }
        
        private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_vm is null)
            {
                return;
            }

            if (_vm.IsMultipleSelection)
            {
                _vm.SelectedItems = Items.SelectedItems;
            }
            else
            {
                _vm.SelectedItem = Items.SelectedItem;
            }
        }
    }
}